package com.cloud.pojo.user;

import com.baomidou.mybatisplus.annotation.TableName;
import com.cloud.comm.BaseModel;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;
import java.util.Date;

/**
 * @version v1.0
 * @author: TianXiang
 * @description:
 * @date: 2021/2/22
 */

@Data
@Accessors(chain = true)
@TableName(value = "user")
public class UserInfo extends BaseModel  implements UserDetails {

    private String username;

    private String password;

    private String role;

    /**
     * 浏览器指纹码
     */
    private String fingerprintCode;

    /**
     * 登录次数
     */
    private Integer loginCount;

    /**
     * 最近登录时间
     */
    private Date lastLoginTime;

    /**
     * 观影失效时间
     */
    private Date expireTime;

    /**
     * 同步指纹的时间
     */
    private Date synchronizeFingerprintTime;

    /**
     * 最近一次同步指纹时间
     */
    private Date synchronizeFingerprintTimeLast;

    @Override
    // 获取权限，这里就用简单的方法
    // 在spring security中，Authorities既可以是ROLE也可以是Authorities
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Collections.singleton(new SimpleGrantedAuthority(role));
    }
    @Override
    public String getUsername() {
        return username;
    }
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }
    @Override
    public boolean isAccountNonLocked() {
        return false;
    }
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }
    @Override
    public boolean isEnabled() {
        return true;
    }
}
